home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / LIBRARY / PASDEMO2 / P584.PAS < prev    next >
Pascal/Delphi Source File  |  1987-09-05  |  2KB  |  75 lines

  1. program TaskList;
  2.  
  3. const Max = 20;   { length of task names }
  4.  
  5. type ListData = packed array[ 1 .. Max ] of char;
  6.      ListPointer = ^Item;
  7.      Item = record
  8.              Data : ListData;
  9.              Next : ListPointer
  10.             end;
  11.  
  12.      Pointer Array = array [ 'A'..'Z' ] of ListPointer;
  13.  
  14. procedure Initialization( var First : PointerArray );
  15. { This procedure initializes appropriate variables }
  16.    var Index : 'A'..'Z';
  17.  
  18.    begin
  19.       for Index := 'A' to 'Z'
  20.           do First[ Index ] := Nil
  21.    end { Initialization };
  22.  
  23. procedure ReadData( var Name : ListData );
  24. {This procedure reads a name from the terminal }
  25.    var Index : integer;
  26.    begin
  27.       Index := 1;
  28.       while ( Index <= Max ) and not Eoln
  29.          do begin
  30.             read( Name[ Index ] );
  31.             Index := Index + 1
  32.          end;
  33.       readln;
  34.       while ( Index <= Max )
  35.          do begin
  36.             Name[ Index ] := NullChar;
  37.             Index := Index + 1
  38.          end;
  39.    end { readData };
  40.  
  41. procedure FindPrevious( Name: ListData; var PrevElt: ListPointer;
  42.                         First: PointerArray );
  43. {This procedure locates the task that comes befire given name on the list.
  44.  If the mane is not found, PrevElt^.Next will be Nil.
  45.  The procedure assures the Name is not the first list element.}
  46.  
  47.  
  48. procedure AddName( var First: PointerArray );
  49. {This procedure reads a task name and inserts it into the list}
  50.    var Let1: char;
  51.        NewItem: ListPointer;
  52.        OldName: ListData;
  53.  
  54.    procedure InsertFirst( NewItem: ListPointer; var First: ListPointer );
  55.    {This procedure inserts the new item at the beginning of the list }
  56.  
  57.    procedure InsertAfterFirst( NewItem, First: ListPointer );
  58.    {The procedure inserts the new item after the start of the list}
  59.  
  60.    begin {AddName}
  61.       New( NewItem );
  62.       Write( 'Enter new task: ' );
  63.       ReadData( NewItem^.Data );
  64.       Let1 := NewItem^.Data[1];
  65.       if First[ Let1 ] = Nil
  66.          then InsertFirst( NewItem, First[ Let1 ] )
  67.          else begin
  68.             writeln( 'Enter ols task which new task should proceed, ' );
  69.             write( 'or enter a blank if new task should be palced "last": ');
  70.             ReadData( OldName );
  71.             if OldName = First[ Let1 ]^.Data
  72.                then InsertFirst( NewItem, First[ Let1 ] )
  73.                else InsertAfterFirst( NewItem, First[ Let1 ] )
  74.               end
  75.    end {AddName} ;